package cn.okcmd.mymqconsumer.web.resps;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * create by caoqg on 2021/7/27
 * 功能说明:
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CommonResp<T> {
    private String code;
    private String msg;
    private T data;

    public static String CODE_SUCC="200";
    public static String CODE_ERR="5000";
    public static String MSG_SUCC = "success";
    public static String MSG_ERR = "sys_error";


    public static <T> CommonResp<T> error(String code,String msg){
        return of(code, msg, null);
    }

    public static <T> CommonResp<T> error(){
        return error(CODE_ERR, CODE_ERR);
    }

    public static <T> CommonResp<T> errorMsg(String msg){
        return error(CODE_ERR, msg);
    }

    public static <T> CommonResp<T> errorCode(String code){
        return error(code, MSG_ERR);
    }

    public static <T> CommonResp<T> succ(T data){
        return of(CODE_SUCC, MSG_SUCC, data);
    }

    public static <T> CommonResp<T> succ(){
        return of(CODE_SUCC, MSG_SUCC, null);
    }

    public static <T> CommonResp<T> of(String code,String msg,T data){
        CommonResp<T> resp = new CommonResp<>();
        resp.setCode(code);
        resp.setMsg(msg);
        resp.setData(data);
        return resp;
    }

}
